% Author: Yang Ge, 302756880@qq.com
% 
% calculate the probability of ith seed selected
% parameter:
% i'th seed vector
% total seeds matrix including origin seeds, sparks seeds, mutation seeds
function result = probability(ith_seed, total_seeds_matrix)
total = 0;
total_seeds_number = size(total_seeds_matrix, 1);
for j = 1:total_seeds_number
    total = total + total_distance(total_seeds_matrix(j,:), total_seeds_matrix);
end
result = total_distance(ith_seed, total_seeds_matrix) / total; 
end

% calculate the total distance of ith seed to others
function result = total_distance(ith_seed, total_seeds_matrix)
total = 0;
total_seeds_number = size(total_seeds_matrix, 1);
for j = 1:total_seeds_number
    total = total + distance(ith_seed, total_seeds_matrix(j,:));
end
result = total;
end

% calculate the distance between two vectors
function result = distance(ith_seed, jth_seed)
result = sqrt(sum((ith_seed - jth_seed).^2));
end
